//
//  ShiJuanShiTiVC.m
//  ZhiBoYuan
//
//  Created by apple on 2018/4/25.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ShiJuanShiTiVC.h"

#import "QuXuanTiCell.h"

#import "PaperViewControllerBuild.h"

static NSString *ident = @"QuXuanTiCell";

@interface ShiJuanShiTiVC ()
<
UITableViewDelegate,
UITableViewDataSource
>
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, assign) NSInteger pageIndex;

@end

@implementation ShiJuanShiTiVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = [NSString stringWithFormat:@"%@试卷试题",self.name];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.tableView];
    
    [self getdate];
}

-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray  = [NSMutableArray array];
    }
    return _dataArray;
}


-(void)getdate
{
    SGParameter *parameter  = [[SGParameter alloc] init];
    
    parameter.body          = @{@"paper_id":self.paperID};
    
    NSString *lastUrl       = @"g=Client&m=Question&a=PaperQuestionList";//g=Client&m=Question&a=PaperQuestionList
    
    //    __weak __typeof(&*self)weakSelf = self;
    
    [SGHttpTool POST:[NSString stringWithFormat:@"%@%@",HTTPP,lastUrl] parameter:parameter sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject;
        
        NNSLog(@"%@",dic);
        
        
        
        NSMutableArray *arr = dic[@"data"][@"question_list"];
        
        NNSLog(@"question_list = %@",arr);
        
        NSMutableArray *danArr=[NSMutableArray array];
        
        NSMutableArray *duoArr= [NSMutableArray array];

        for (NSDictionary *dic in arr) {
            Questiion *q = [[Questiion alloc]initWithDictionary:dic];
            
            if ([q.ques_model integerValue] == 2) {
                [duoArr addObject:dic];
            }else{
                [danArr addObject:dic];
            }
            
        }
        
        self.dataArray = arr;
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        
    }];
}

-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, Screenheight) style:(UITableViewStylePlain)];
        
        _tableView.estimatedRowHeight = 44.0f;//推测高度，必须有，可以随便写多少
        
        _tableView.rowHeight = UITableViewAutomaticDimension;
        
        _tableView.delegate = self;
        
        _tableView.dataSource = self;
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        
        [_tableView registerNib:[UINib nibWithNibName:ident bundle:nil] forCellReuseIdentifier:ident];
    }
    return _tableView;
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    QuXuanTiCell *cell= [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];
    
    [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
    
    Questiion *q = [[Questiion alloc]initWithDictionary:self.dataArray[indexPath.row]];
    
    cell.questiion = q;
    cell.addbutton.hidden = YES;

    return cell;
    
}




//-(void)adddste:(NSString *)set {
//
//    //创建富文本
//    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:set];
//
//
//    [attri addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,str.length)];
//    //NSTextAttachment可以将要插入的图片作为特殊字符处理
//    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
//    //定义图片内容及位置和大小
//    attch.image = [UIImage imageNamed:imageName];
//
//    if (imageFram.size.width > 0) {
//        attch.bounds = imageFram;
//    }else{
//        attch.bounds = CGRectMake(0, -1, 12, 12);
//    }
//
//    //创建带有图片的富文本
//    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
//
//    //将图片放在最后一位
//    //[attri appendAttributedString:string];
//    //将图片放在第一位
//    [attri insertAttributedString:string atIndex:0];
//    //用label的attributedText属性来使用富文本
//
//}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    PaperViewController * paper;
    paper = [PaperViewControllerBuild createIntelligentAllAnalyViewControllerWithData:@{}];
    paper.ID = [_dataArray[indexPath.row] valueForKey:@"id"];
    
    paper.answerType = @"question_id";
    paper.url = QuestionInfo;
    paper.isComeFromShongCang = YES;
    [ZYCurrentViewController().navigationController pushViewController:paper animated:YES];

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
